package fragments.shopactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.travel.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

/**
 * Created by Administrator on 2016/10/19.
 */
public class ViewPageActivity extends AppCompatActivity {
    @Bind(R.id.viewpage_title)
    TextView viewpageTitle;
    @Bind(R.id.viewpage_wv)
    WebView viewpageWv;
    @Bind(R.id.viewpage_iv_back)
    ImageView viewpageIvBack;
    private String url;
    private String title,pic;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shop_viewpage_activity);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        url = intent.getStringExtra("url");
//        Log.i("TAG","------url----"+url);
        title = intent.getStringExtra("title");
        viewpageTitle.setText(title);
        pic=intent.getStringExtra("pic");
        initWebView();
        ShareSDK.initSDK(this);//初始化sharedsdk
    }
    /**
     * 一键分享
     */
    public void sharedOneKeyV(View view){
        //1.创建一键分享的对象
        OnekeyShare onekeyShare=new OnekeyShare();
        onekeyShare.disableSSOWhenAuthorize();//关闭sso授权
        //设置一键分享的内容
        onekeyShare.setTitle(title);
        onekeyShare.setText("游谱旅行");
        onekeyShare.setTitleUrl(url);
        onekeyShare.setUrl(url);
        onekeyShare.setImageUrl(pic);
        onekeyShare.setSite(getString(R.string.app_name));
        onekeyShare.show(this);
    }
    private void initWebView() {
        viewpageWv.getSettings().setJavaScriptEnabled(true);
        viewpageWv.setWebChromeClient(new WebChromeClient());
        //点击网页中的超链接时不弹出浏览器的窗口 在webview控件中加载url
        viewpageWv.setWebViewClient(new WebViewClient());
        // loadUrl()该方法直接加载网络地址
        viewpageWv.loadUrl(url);
        viewpageIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode== KeyEvent.KEYCODE_BACK){
            if(viewpageWv.canGoBack()){
                viewpageWv.goBack();//goBack() 表示返回webview中的上一页面
            }else{
                finish();
            }
        }
        return true;
    }
}